﻿using Yxinmt.Interface;
using Yxinmt.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Yxinmt.Windows
{
    public class PageAction : IPageAction
    {
        public void ToPage(IWindow window, IControl control, Dictionary<string, object> eventAction)
        {
            string pageName = eventAction.GetStringValue("PageName");
            new MainWindow(window.Window, pageName, eventAction);
        }

        public void SetControlVisible(IWindow window, IControl control, Dictionary<string, object> eventAction)
        {
            string visibleNames = eventAction.GetStringValue("VisibleNames");
            string hideNames = eventAction.GetStringValue("HideNames");
            if (!string.IsNullOrEmpty(visibleNames))
            {
                var list = (from a in visibleNames.Split(',')
                            from b in window.ControlList
                            where a == b.Name
                            select b);
                foreach (var b in list)
                {
                    b.SetVisible(true);
                }
            }

            if (!string.IsNullOrEmpty(hideNames))
            {
                var list = (from a in hideNames.Split(',')
                            from b in window.ControlList
                            where a == b.Name
                            select b);
                foreach (var b in list)
                {
                    b.SetVisible(false);
                }
            }
        }
    }
}
